﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HR.Appointments.Service.Tools
{
    internal class EmailGatway
    {
        public static object _syncObject = new object();

        public static string CreateMessage(OrderEntity order)
        {
            System.Diagnostics.Debug.Assert(order.Company != null, "Company is null");
            StringBuilder sb = new StringBuilder();
            return string.Format(
                "\nKæri/a {0}\n\n\tÞú átt pantaðan tíma þann {1} kl.{2} hjá {3}.\n\nKveðja,\nTímaskráning.is",
                order.Person.Name,
                order.BookingDate.ToShortDateString(),
                order.FromTime.ToString(),
                order.Company.Name);
        }


        public static void Send(OrderEntity order)
        {
            Send(order.Person.Email, EmailGatway.CreateMessage(order));
        }

        public static void Send(string email, string message)
        {
            if(!string.IsNullOrEmpty(email.Trim()))
            {
                lock (_syncObject)
                {
                    Console.WriteLine(message);
                    StreamWriter file = new StreamWriter("FakeEmail.txt", true);
                    file.WriteLine(email.ToString() + " " + message.ToString());
                    file.Flush();
                    file.Close();
                }
            }
        }
    }
}
